#include <QtGui>
#include "mediaplayer.h"

#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QMediaMetaData>

#include "mainwindow.h"



MediaPlayer::MediaPlayer(QWidget *pr) : QWidget(pr)
{
    m_player = new QMediaPlayer();

    QObject::connect(m_player, SIGNAL(metaDataChanged()), this, SLOT(updateSongInfo()));
    QObject::connect(m_player, SIGNAL(durationChanged(qint64)), this, SLOT(updateSongInfo()));


}
void MediaPlayer::updateSongInfo()
{

       if(m_player->isMetaDataAvailable())
       {
           MainWindow* wnd = ((MainWindow*)(this->parent()));
           qDebug() << m_player->metaData(QMediaMetaData::AudioBitRate);

           QString info = m_player->metaData(QMediaMetaData::Publisher).toString();
           wnd->setInfo(info);
       }




}

void MediaPlayer::Play(QString file)
{
    m_player->setMedia(QUrl::fromUserInput(file));
    m_player->play();


}
void MediaPlayer::Stop()
{
    m_player->stop();
}
void MediaPlayer::Pause()
{
    m_player->pause();
}
void MediaPlayer::setVolume(int vol)
{
    m_player->setVolume(vol);
}

int  MediaPlayer::getVolume()
{
    return m_player->volume();
}
